package org.malred.jetpackcomposebasic

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.malred.jetpackcomposebasic.ui.theme.JetpackComposeBasicTheme

class MainActivity04 : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            // 基本主题, 可以使用它的深色主题
            JetpackComposeBasicTheme {
                MessageCard(Message("androdid", "jetpack compose"))
            }
        }
    }

    @Composable // compose 控件
    fun MessageCard(msg: Message) {
        Row(
            modifier = Modifier
                .padding(all = 8.dp)
//                .background(Color.Green),
                .background(MaterialTheme.colorScheme.background),
        ) {
            Image(
                painter = painterResource(id = R.drawable.test),
                // 无障碍模式下, 会语言读出这个描述文本
                contentDescription = null,
                // 图片描述
                modifier = Modifier
                    .size(40.dp)
                    // 裁剪
                    .clip(CircleShape)
            )
            // column: vertical垂直排列
            Column {
                // compose: 文本控件
                Text(text = msg.author)
                // 间距
                Spacer(modifier = Modifier.height(4.dp))
                Text(text = msg.body)
            }
        }
    }
}
